package com.smart_campus.teg.controller;

import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.common.ResultObj;
import com.smart_campus.teg.common.TEGResultObj;
import com.smart_campus.teg.domain.Course;
import com.smart_campus.teg.domain.Major;
import com.smart_campus.teg.service.CourseService;
import com.smart_campus.teg.vo.CourseVo;
import com.smart_campus.teg.vo.MajorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @aytgor 陈鹏
 * @date 2020/6/19 15:13
 */

@RestController
@RequestMapping("Course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 查询全部的课程
     * @return DataGridView
     */
    @RequestMapping("CourseList")
    public DataGridView CourseList(CourseVo courseVo){
        return courseService.CourseList(courseVo);
    }

    /**
     * 添加课程
     * @param courseVo
     * @return TEGResultObj
     */
    @RequestMapping("CourseAdd")
    public TEGResultObj CourseAdd(CourseVo courseVo){
        try {
            courseService.CourseAdd(courseVo);
            return TEGResultObj.COURSE_INSERT_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return TEGResultObj.COURSE_INSERT_NO;
        }
    }

    /**
     * 删除课程方法
     * @param id
     * @return TEGResultObj
     */
    @RequestMapping("Coursedelete")
    public TEGResultObj Coursedelete(Integer id){
        try {
            courseService.CourseDelete(id);
            return TEGResultObj.COURSE_DELETE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return TEGResultObj.COURSE_DELETE_NO;
        }
    }

    /**
     * 批量删除课程方法
     * @param ids
     * @return TEGResultObj
     */
    @RequestMapping("CoursedeleteBatch")
    public TEGResultObj CoursedeleteBatch(Integer[] ids){
        try {
            for (Integer id : ids) {
                courseService.CourseDelete(id);
            }
            return TEGResultObj.COURSE_DELETE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return TEGResultObj.COURSE_DELETE_NO;
        }
    }


    /**
     * 修改课程方法
     * @param courseVo
     * @return TEGResultObj
     */
    @RequestMapping("CourseUpdateMajor")
    public TEGResultObj CourseUpdateMajor(CourseVo courseVo){
        try {
            courseService.CourseUpdate(courseVo);
            return TEGResultObj.COURSE_UPDATE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return TEGResultObj.COURSE_UPDATE_NO;
        }
    }

}
